<?php
require('Usuario.class.php');

$modo = (isset($_GET['modo'])) ? $_GET['modo']:0;
switch($modo){
    case 1: //Consultar Grid
        if(isset($_GET['modo']) == 1){
            $page           = $_POST['page'];
            $rp             = $_POST['rp'];
            $sortname       = $_POST['sortname'];
            $sortorder      = $_POST['sortorder'];
            $query          = $_POST['query'];
            $letter_pressed = isset($_POST['letter_pressed'])?$_POST['letter_pressed']:null;
            $qtype          = $_POST['qtype'];
            $obj            = new Usuario();
            $obj->consultar_grid($page, $rp, $sortname, $sortorder, $query, $letter_pressed, $qtype);
        }
        break;
    case 2: //Insertar
        if(isset($_POST['submit'])){
            $campo[0]  = htmlspecialchars(trim($_POST['nombre']));
            $campo[1]  = htmlspecialchars(trim($_POST['apellido']));
            $campo[2]  = htmlspecialchars(trim($_POST['email']));
            $campo[3]  = htmlspecialchars(trim($_POST['login']));
            $campo[4]  = htmlspecialchars(trim($_POST['pass']));
            $campo[5]  = date("Ymd");
            $campo[6]  = date("His");   
            $obj       = new Usuario();
            if ( $obj->insertar($campo) == true) echo 1;
            else   echo 0;
        }
        break;
    case 3: //Modificar
        if(isset($_POST['submit'])){
            $id = $_POST['id'];
            $campo[0]  = htmlspecialchars(trim($_POST['nombre']));
            $campo[1]  = htmlspecialchars(trim($_POST['apellido']));
            $campo[2]  = htmlspecialchars(trim($_POST['email']));
            //$campo[3]  = htmlspecialchars(trim($_POST['login']));
            $campo[3]  = htmlspecialchars(trim($_POST['pass']));
            $obj        = new Usuario();
            if ( $obj->actualizar($campo, $id) == true){
                   echo 1;
            }else{
                   echo 0;
            } 
        }        
        break;
    case 4://Eliminar
        if(isset($_POST['submit'])){
            $id = $_POST['id'];
            $obj    = new PresentacionP();
            if ( $obj->eliminar($id) == true){
                   echo 1;
            }else{
                   echo 0;
            } 
        }             
        break;
    default:
        echo "Debe seleccionar un modo: \n1. Consultar Grid\n2. Insertar\n3. Modificar\n4. Eliminar";
}

?>
